// pages/calling/pring-rule.js
var config = require('../../config.js');
var util = require('../../network_util.js');
var commonjs = require('../../common.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      '../../images/pic1@2x.png',
      '../../images/pic2@2x.png',
      '../../images/pic3@2x.png',
    ],
    openingImgUrls:[],
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 1000,
    priceRules:{},
    index: 0
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log("cityId: " + app.globalData.fromInfo.cityId);
    that.getRules(app.globalData.fromInfo.cityId);
  },
  getRules: function(cityId){
    var that = this;
    util._get(config.caculateDetail + "?serviceType=1&cityId=" + cityId,
      function (res) {
        console.log(res);
        if(res.statusCode == 200){
          if(res.data.code == 200){
            that.setData({priceRules: res.data.data});
            var tmp = new Array();
            for(var i = 0; i<res.data.data.length; i++){
              if(i<=2){
                tmp.push(that.data.imgUrls[i]);
              }
            }
            that.setData({ openingImgUrls: tmp});
          } else {
            wx.showToast({
              title: '获取计价规则失败(' + res.data.code  + ')',
            })

          }
        }else{
          wx.showToast({
            title: '系统错误(' + res.statusCode + ')',
          })
        }
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  swiperChange: function(e){
    console.log(e);
    this.setData({index: e.detail.current});
  }
})